﻿using UnityEngine;
using System.Collections;

public class MenuManager : MonoBehaviour {
	bool starting = false;
	float delay = 2.0f;
	public GameObject canvas;
		// Use this for initialization
	void Start () {
		if (AudioController.audio_controller){
			if (!AudioController.audio_controller.GetSound("Ambiance_Creatures").isPlaying)
				AudioController.audio_controller.GetSound("Ambiance_Creatures").Play();
		}
	}
	
	
	// Update is called once per frame
	void Update () {
		if (starting){
			delay-=Time.deltaTime;
			if (delay <=0)
				gotoGame();
		}
	}
	
	void gotoGame(){
		Application.LoadLevel(1);
	}
	
	public void stopMusicNOW(){
		AudioController.audio_controller.GetSound("Ambiance_Creatures").Stop();
		AudioController.audio_controller.GetSound("Spooky_Loud").Play();
		starting = true;
		FadeAllOut();
	}
	
	void FadeAllOut(){
		foreach(Transform child in canvas.transform){
			if (child.GetComponent<Animator>()){
				child.GetComponent<Animator>().SetBool("leaving",true);
			}
		}
	}
	
	public void gotoHighScores(){
		Application.LoadLevel(2);
	}
	
	public void gotoCredits(){
		Application.LoadLevel(3);
	}
}
